package com.ruoyi.framework.task;

import com.ruoyi.project.system.service.IResdelService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component("ResdelTask")
public class ResdelTask {

    private static final Logger log = LoggerFactory.getLogger(ResdelTask.class);

    @Autowired
    private IResdelService resdelService;

    /**
     * 每天凌晨2点执行一次
     * 清理：当天之前（即昨天及更早）的所有预约记录（不限制状态）
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void cleanReservationsBeforeToday() {
        log.info("定时任务【清理当天之前的所有预约记录】开始执行...");
        boolean result = resdelService.cleanReservationsBeforeToday();
        if (result) {
            log.info("定时任务【清理当天之前的所有预约记录】执行成功。");
        } else {
            log.error("定时任务【清理当天之前的所有预约记录】执行失败！");
        }
    }
}